package com.haozhen.config;

import com.haozhen.component.DataSourceChangeListerner;
import com.haozhen.component.DataSourceChangeServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author haozhen
 * @email haozh@ync1.com
 * @date 2020/10/24  13:18
 */
@Configuration
public class DynamicDataSourceConfig {

    @Bean
    public DataSourceChangeListerner getDataSourceChangeListerner(){
        DataSourceChangeListerner dataSourceChangeListerner =  new DataSourceChangeListerner().initZkClient();
        dataSourceChangeListerner.initDataSource();
        dataSourceChangeListerner.registerChangeListerner();
        return dataSourceChangeListerner;
    }

    @Bean
    public DataSourceChangeServer getDataSourceChangeServer(){
        DataSourceChangeServer dataSourceChangeServer =  new DataSourceChangeServer().initZkClient();
        return dataSourceChangeServer;
    }
}
